package com.blood.modules.system.controller;

import com.blood.core.resp.GlobalResultStatus;
import com.blood.core.resp.PageResult;
import com.blood.core.resp.ResponseResult;
import com.blood.core.util.bean.ListUtils;
import com.blood.modules.system.dto.req.SysOrgSchemaPageReq;
import com.blood.modules.system.dto.req.SysOrgSchemaReq;
import com.blood.modules.system.dto.req.SysOrgSchemaSaveReq;
import com.blood.modules.system.dto.resp.SysOrgSchemaInfoResp;
import com.blood.modules.system.dto.resp.SysOrgSchemaPageResp;
import com.blood.modules.system.service.ISysOrgSchemaService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 组织架构Controller
 *
 * @author daoren
 * @date 2022-05-12 09:14:45
 */
@Api(value = "组织架构", tags = "组织架构")
@ApiSort(906)
@RestController
@RequestMapping("/sys/org")
public class SysOrgSchemaController {
    /**
     * 组织架构服务.
     */
    @Autowired
    private ISysOrgSchemaService sysOrgSchemaService;

    /**
     * 分页查询列表
     *
     * @param req
     * @return 分页数据
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "组织架构列表-分页")
    public ResponseResult<PageResult<SysOrgSchemaPageResp>> pageList(@RequestBody SysOrgSchemaPageReq req) {
        return sysOrgSchemaService.pageList(req);
    }

    /**
     * 获取.
     *
     * @param req 请求参数
     * @return 列表信息
     */
    @ApiOperation(value = "获取组织架构列表信息")
    @PostMapping(value = "/getListInfo")
    public ResponseResult<List<SysOrgSchemaInfoResp>> getListInfo(@RequestBody SysOrgSchemaReq req) {
        return GlobalResultStatus.SUCCESS.toResult().response(ListUtils.copyProperties(sysOrgSchemaService.queryList(req), SysOrgSchemaInfoResp.class));
    }

    @ApiOperation(value = "添加组织架构信息")
    @PostMapping(value = "/add")
    public ResponseResult<Void> add(@RequestBody @Validated SysOrgSchemaSaveReq req) {
        return sysOrgSchemaService.saveInfo(req);
    }

    @ApiOperation(value = "修改组织架构信息")
    @PostMapping(value = "/update")
    public ResponseResult<Void> update(@RequestBody @Validated SysOrgSchemaSaveReq req) {
        return sysOrgSchemaService.updateInfo(req);
    }

    /**
     * 更改组织状态
     *
     * @param id 用户账号
     * @return 返回账户信息
     */
    @ApiOperation(value = "更改组织状态")
    @GetMapping(value = "/updateStatus")
    public ResponseResult<Void> updateStatus(@ApiParam(value = "组织id", type = "String") @RequestParam("id") String id) {
        return sysOrgSchemaService.updateStatus(id);
    }

    /**
     * 根据id获取详情
     *
     * @param id
     * @return 详情
     */
    @GetMapping("/findDetailById")
    @ApiOperation(value = "获取组织架构详情")
    public ResponseResult<SysOrgSchemaInfoResp> findDetailById(@ApiParam(value = "id", type = "String") @RequestParam("id") String id) {
        return sysOrgSchemaService.findDetailById(id);
    }

    /**
     * 根据id删除数据
     *
     * @param id
     * @return 详情
     */
    @GetMapping("/deleted")
    @ApiOperation(value = "删除数据")
    public ResponseResult<Void> deleted(@ApiParam(value = "组织id", type = "String") @RequestParam("id") String id) {
        return sysOrgSchemaService.deleted(id);
    }
}
